<?        
$data=$HTTP_RAW_POST_DATA;                                                 
if (isset($HTTP_RAW_POST_DATA)) {                                                 
    $input = $HTTP_RAW_POST_DATA;                                                 
} else if (strlen($HTTP_POST_VARS["input"])>0) {                                                 
    $input = stripslashes($HTTP_POST_VARS["input"]);                                                 
} else {                                                 
    $input = implode("\r\n", file('php://input'));                                                 
}               
         
define ("CONFIG_FILE", "C:/Program Files/Apache Group/Apache2/conf/httpd.conf");         
header ("Content-Type: text/xml");        
        

                
if ($input=="") $input="<soap:syntax xmlns:soap='whatever'/>";        



$action="";                               
$arguments=array();                               
$resultxml="";                               

if ($dom=domxml_open_mem($input))                                                        
{                                                         
                                                                             
    foreach ($dom->get_elements_by_tagname("Body") as $body)                                                     
    {                                                                  
        foreach ($body->child_nodes() as $x)                                                     
        {                                                         
            $action=$x->node_name();                                    
            foreach ($x->child_nodes() as $arg)                                                     
            {                               
                $arguments[$arg->node_name()]=$arg->get_content();                              
            }                              
        }      
    }    
                      
             
    if ($action=="getVirtualFolders")        
    {        
        $x=load_alias_list();        
        $resultxml= '<' . $action . 'Response xmlns="http://tempuri.org/">';        
        while (list($path,$name)=each ($x))        
        {        
            $resultxml.= '<' . $action . 'Result>' . $name . '?' . $path . '</' . $action . 'Result>';        
        }        
        $resultxml.= '</' . $action . 'Response>';        
    }                      
             
    if ($action=="getFolder")        
    {        
        $coll=new PathCollection();  
        $folder=$arguments["foldername"];         
        $ah=@opendir( $folder );         
        $resultxml= '<' . $action . 'Response xmlns="http://tempuri.org/">';        
        $dir=array();$doc=array();        
        while (! ( ( $temp_file = readdir ( $ah ) ) == false ) )         
        {        
            $fld=new PathInfo();  
            $path= $folder . '/' . $temp_file;        
            if ( $temp_file == "." || $temp_file == ".."  )         
            {           
            }          
            else if (is_dir($path))         
            { // mark sub-folders    
                $fld->filetype="File Folder";         
                $fld->fullpath=htmlentities($path);         
                $fld->filename=htmlentities ($temp_file);      
                $coll->ArrayOfPathInfo[]=$fld;     
            }        
            else if (preg_match('/\.(wmv|nsv|mpg|mpeg|asf|mp4|mp3|jpg|png|gif)$/i',$temp_file,$nf))        
            {         
                $date=date('n/j/Y h:i A',filemtime($path));        
                $size=number_format( floor (filesize($path)/1024), 0, '', ',' );        
                $type=strtoupper ($nf[1]);       
                $fld->filesize=$size;         
                $fld->filedate=$date;         
                $fld->filetype=$type;         
                $fld->fullpath=htmlentities($path);         
                $fld->filename=htmlentities ($temp_file);   
                $coll->ArrayOfPathInfo[]=$fld;     
            }        
        }          
        $resultxml.= '<' . $action . 'Result>' . $coll->serialize() . '</' . $action . 'Result>';        
        $resultxml.= '</' . $action . 'Response>';                 
    }                      
             
    if ($action=="getNSVDimensions")        
    {        
        $data = read_vp3 ($arguments["filename"]);        
        $resultxml= '<getNSVDimensionsResponse xmlns="http://tempuri.org/">                                                   
                        <getNSVDimensionsResult>' . $data[0] . '</getNSVDimensionsResult>                                                   
                        <getNSVDimensionsResult>' . $data[1] . '</getNSVDimensionsResult>                                                   
                     </getNSVDimensionsResponse>';        
    }        

         
    if ($resultxml!="")                      
    {                                                                           
        $output = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">                                                   
               <soap:Body>' . $resultxml . '</soap:Body></soap:Envelope>';                                         
        echo $output;                           
$fp=fopen ("wsdl_out_" . time() . ".txt", "w");                                                 
fwrite ($fp,$output);                                                 
fclose($fp);        
        exit;                                           
    }                      
}        
echo $input;        
                                           
function read_vp3($path)         
{         
    $reader=@fopen ($path,"r");         
    if ($reader)        
    {          
        $arr=array();        
        fread ($reader,12);         
        $arr[]  = fread ($reader,2);         
        $arr[]  = fread ($reader,2);         
        for ($x=0;$x<2;$x++) $arr[$x]= BigEndian2Int(strrev($arr[$x]))  ;        
        return $arr;        
    }        
   # echo $path;        
    return array(320,240);        
}         

function load_alias_list() // load_alias_list        
{        
    /*$conf=implode ('',file(CONFIG_FILE));        
    if (preg_match_all('/Alias\s(.*)\s"(.*)"/', $conf, $alii))        
    {        
        for($e=0;$e<count($alii[1]);$e++)        
        {         
            if (is_dir($alii[2][$e]))        
            {        
                 while ( substr($alii[1][$e],0,1)=="/" ) $alii[1][$e] = substr( $alii[1][$e], 1);        
                 while ( substr($alii[1][$e],strlen($alii[1][$e])-1)=="/" ) $alii[1][$e] = substr( $alii[1][$e], 0, strlen($alii[1][$e])-1 );        
                 while ( substr($alii[2][$e],strlen($alii[2][$e])-1)=="/" ) $alii[2][$e] = substr( $alii[2][$e], 0, strlen($alii[2][$e])-1 );        
                 $aliaslist[$alii[2][$e]] = $alii[1][$e];        
            }        
        }        
    }*/        
    $aliaslist["/homepages/13/d97505132/htdocs"]="";        
    return $aliaslist;        
} // load_alias_list         

     function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {        
         $intvalue = 0;        
         $bytewordlen = strlen($byteword);        
         for ($i = 0; $i < $bytewordlen; $i++) {        
             if ($synchsafe) { // disregard MSB, effectively 7-bit bytes        
                 $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7);        
             } else {        
                 $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));        
             }        
         }        
         if ($signed && !$synchsafe) {        
             // synchsafe ints are not allowed to be signed        
             switch ($bytewordlen) {        
                 case 1:        
                 case 2:        
                 case 3:        
                 case 4:        
                     $signmaskbit = 0x80 << (8 * ($bytewordlen - 1));        
                     if ($intvalue & $signmaskbit) {        
                         $intvalue = 0 - ($intvalue & ($signmaskbit - 1));        
                     }        
                     break;        
         
                 default:        
                     die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2Int()');        
                     break;        
             }        
         }        
         return $intvalue;        
     }        


    function select_single_node($node, $value) // select_single_node                                                                                                                                                           
    {                                                                                                                                                              
        $xpath = xpath_new_context($node);                                                                                                                                                           
        $xnode = xpath_eval($xpath, $value);                                                                                                                                                            
        foreach ($xnode->nodeset as $node)                                                                                                                                                           
        {                                                                                                                                                            
            return $node;                                                                                                                                                            
        }                                                                                                                                                            
        return false;                                                                                                                                                             
    } // select_single_node                                                                                                                                                           
    function select_nodes($node, $value) // select_nodes                                                                                                                                                           
    {                                                                                                                                                              
        $xpath = xpath_new_context($node);                                                                                                                                                           
        $xnode = xpath_eval($xpath, $value);                                                                                                                                                             
        return $xnode->nodeset;                                                                                                                                                             
    } // select_nodes                                                                                                                                                           


                                          

class PathInfo  
{  
    var $filename;  
    var $fullpath;  
    var $filesize;  
    var $filetype;  
    var $filedate;  
    function serialize()  
    {  
        $output="";  
        $output.="<filename>" . $this->filename . "</filename>";  
        $output.="<fullpath>" . $this->fullpath . "</fullpath>";  
        $output.="<filesize>" . $this->filesize . "</filesize>";  
        $output.="<filetype>" . $this->filetype . "</filetype>";  
        $output.="<filedate>" . $this->filedate . "</filedate>";   
        return $output;          
    }      
}  
    
class PathCollection  
{  
    var $ArrayOfPathInfo = array();  
    function serialize()  
    {  
        $output="";  
        for ($i=0;$i < sizeof($this->ArrayOfPathInfo);$i++)  
        {  
            $output.="<ArrayOfPathInfo>";  
            $output.=$this->ArrayOfPathInfo[$i]->serialize ();  
            $output.="</ArrayOfPathInfo>";  
        }   
        return $output;          
    }      
}  
    


?>